package page.sample;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import page.MyFirstWebPage;
import entity.Ticket;
import entity.User;

public class ShowTicketPage extends WebPage {
	
	public ShowTicketPage(final User user)
	{

		add(new Link("ShowFlight") {

			@Override
			public void onClick() {
				setResponsePage(new FlightPage(user));
			}

		});

		add(new Link("ShowTicket") {

			@Override
			public void onClick() {
				setResponsePage(new ShowTicketPage(user));

			}

		});

		add(new Link("exit") {

			@Override
			public void onClick() {
				setResponsePage(new MyFirstWebPage());

			}

		});
		
		add(new DataView<Ticket>("table-rows", new ListDataProvider<Ticket>(
				user.getTickets())) {
			@Override
			protected void populateItem(final Item<Ticket> item) {
				final Ticket ticket = item.getModelObject();
				// add data for table cell in row
				item.add(new Label("name", ticket.getNameFlight()));
				item.add(new Label("date", ticket.getDate()));
				item.add(new Label("time", ticket.getTime()));
				item.add(new Label("price", ticket.getPrice()));
				item.add(new Label("baggage", ticket.isBaggage()));
				item.add(new Label("firstRegistration", ticket.isFirstRegistration()));

				}
		});
	}

}
